package homework.printyourself.danmu.util;

import java.awt.Color;
import java.util.Random;

public class ColorUtil {

    private static Random random = new Random(System.currentTimeMillis());

    public static Color getRandomColor() {
        return new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256));
    }

    public static Color fromHexString(String hex) {
        int colorR = Integer.parseInt(hex.substring(0, 2), 16);
        int colorG = Integer.parseInt(hex.substring(2, 4), 16);
        int colorB = Integer.parseInt(hex.substring(4, 6), 16);
        int colorA = 255;
        String colorAHex = hex.substring(6, 8);
        if(colorAHex.length() == 2)
            colorA = Integer.parseInt(colorAHex, 16);

        return new Color(colorR, colorG, colorB, colorA);
    }
}
